/*
 * RegimenEliminarFrame.java
 *
 * Created on 30 de abril de 2008, 03:21 PM
 */
package org.contabilidad.regimen;

import org.mybeans.Sesion;
import org.mybeans.SubGrupoRegimenBeans;
import org.mybeans.RegimenBeans;
 
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

/**
 *
 * @author  avbravo
 */
public class RegimenActualizarFrame extends javax.swing.JFrame {

    Sesion sesion;
    RegimenBeans regimenBeans;
    SubGrupoRegimenBeans subGrupoRegimenBeans;
 boolean focoRegimen = true;
    boolean focoSubGrupo = false;
    /** Creates new form RegimenEliminarFrame */
    public RegimenActualizarFrame() {
        initComponents();
           /*
             * Fondo
             */

            
              
             

             
             

            /*
             * fin del fondo
             */
        sesion = new Sesion();
        regimenBeans = new RegimenBeans();
        subGrupoRegimenBeans = new SubGrupoRegimenBeans();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTextFieldIdRegimen = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldRegimen = new javax.swing.JTextField();
        jButtonConsultarRegimen = new javax.swing.JButton();
        jButtonBuscarRegimen = new javax.swing.JButton();
        jButtonRegresar = new javax.swing.JButton();
        jButtonLimpiar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldIdSubGrupoRegimen = new javax.swing.JTextField();
        jButtonConsultarSubGrupoRegimen = new javax.swing.JButton();
        jButtonBuscarSubGrupo = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldSubGrupoRegimen = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldValor = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldLimiteInferior = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldLimiteSuperior = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextFieldDescripcion = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaObservacion = new javax.swing.JTextArea();
        jButtonGuardar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Actualizar Regimen");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jTextFieldIdRegimen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldIdRegimenActionPerformed(evt);
            }
        });

        jLabel5.setText("Codigo");

        jLabel6.setText("Regimen");

        jButtonConsultarRegimen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/consultar.png"))); // NOI18N
        jButtonConsultarRegimen.setToolTipText("Consultar");
        jButtonConsultarRegimen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConsultarRegimenActionPerformed(evt);
            }
        });

        jButtonBuscarRegimen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/search.png"))); // NOI18N
        jButtonBuscarRegimen.setToolTipText("Buscar");
        jButtonBuscarRegimen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarRegimenActionPerformed(evt);
            }
        });

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar.setToolTipText("Regresar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jButtonLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/escoba.png"))); // NOI18N
        jButtonLimpiar.setToolTipText("Limpiar");
        jButtonLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLimpiarActionPerformed(evt);
            }
        });

        jLabel3.setText("Cod. SubGrupo");

        jTextFieldIdSubGrupoRegimen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldIdSubGrupoRegimenActionPerformed(evt);
            }
        });

        jButtonConsultarSubGrupoRegimen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/consultar.png"))); // NOI18N
        jButtonConsultarSubGrupoRegimen.setToolTipText("Consultar");
        jButtonConsultarSubGrupoRegimen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConsultarSubGrupoRegimenActionPerformed(evt);
            }
        });

        jButtonBuscarSubGrupo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/search.png"))); // NOI18N
        jButtonBuscarSubGrupo.setToolTipText("Buscar");
        jButtonBuscarSubGrupo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarSubGrupoActionPerformed(evt);
            }
        });

        jLabel4.setText("Sub Grupo");

        jTextFieldSubGrupoRegimen.setEditable(false);

        jLabel7.setText("Valor");

        jLabel8.setText("Minimo");

        jLabel9.setText("Maximo");

        jLabel10.setText("Descripcion");

        jLabel11.setText("Observacion");

        jTextAreaObservacion.setColumns(20);
        jTextAreaObservacion.setRows(5);
        jScrollPane1.setViewportView(jTextAreaObservacion);

        jButtonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/save.png"))); // NOI18N
        jButtonGuardar.setToolTipText("Actualizar");
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5))
                        .addGap(28, 28, 28)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldIdRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(29, 29, 29)
                                .addComponent(jButtonConsultarRegimen)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonBuscarRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jTextFieldRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 643, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel7)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11))
                        .addGap(6, 6, 6)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldValor, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(40, 40, 40)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldLimiteInferior, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(32, 32, 32)
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldLimiteSuperior, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldIdSubGrupoRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(43, 43, 43)
                                .addComponent(jButtonConsultarSubGrupoRegimen)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonBuscarSubGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jTextFieldDescripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 625, Short.MAX_VALUE)
                            .addComponent(jTextFieldSubGrupoRegimen)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldIdRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addComponent(jButtonConsultarRegimen))
                    .addComponent(jButtonBuscarRegimen))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldIdSubGrupoRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonBuscarSubGrupo)
                    .addComponent(jButtonConsultarSubGrupoRegimen))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldSubGrupoRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jTextFieldLimiteInferior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldLimiteSuperior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTextFieldDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonGuardar, javax.swing.GroupLayout.DEFAULT_SIZE, 44, Short.MAX_VALUE)
                    .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonConsultarRegimenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConsultarRegimenActionPerformed
 ConsultarRegimen();
    
}//GEN-LAST:event_jButtonConsultarRegimenActionPerformed

private void jButtonBuscarRegimenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarRegimenActionPerformed
 

    RegimenBusquedaFrame regimenBusquedaFrame = new RegimenBusquedaFrame();
    regimenBusquedaFrame.setLocationRelativeTo(null);
    regimenBusquedaFrame.setVisible(true);
    focoRegimen = true;
    focoSubGrupo = false;
}//GEN-LAST:event_jButtonBuscarRegimenActionPerformed

private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed
 
    dispose();
}//GEN-LAST:event_jButtonRegresarActionPerformed

private void jButtonLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLimpiarActionPerformed
 
    Limpiar();
}//GEN-LAST:event_jButtonLimpiarActionPerformed

private void jButtonConsultarSubGrupoRegimenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConsultarSubGrupoRegimenActionPerformed
 
    ConsultarSubGrupoRegimen();
}//GEN-LAST:event_jButtonConsultarSubGrupoRegimenActionPerformed

private void jButtonBuscarSubGrupoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarSubGrupoActionPerformed
 
    SubGrupoRegimenBusquedaFrame subGrupoRegimenBusquedaFrame = new SubGrupoRegimenBusquedaFrame();
    subGrupoRegimenBusquedaFrame.setLocationRelativeTo(null);
    subGrupoRegimenBusquedaFrame.setVisible(true);
     focoRegimen = false;
    focoSubGrupo = true;
}//GEN-LAST:event_jButtonBuscarSubGrupoActionPerformed

private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed
 
    try {
        String idRegimen = this.jTextFieldIdRegimen.getText();
        if (idRegimen == null || idRegimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el codigo de regimen", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldIdRegimen.requestFocus();
            return;
        }

        String Regimen = this.jTextFieldRegimen.getText();
        if (Regimen == null || Regimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el nombre del regimen", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldRegimen.requestFocus();
            return;
        }



        String idSubGrupoRegimen = this.jTextFieldIdSubGrupoRegimen.getText();
        if (idSubGrupoRegimen == null || idSubGrupoRegimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el codigo de subgrupo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldIdSubGrupoRegimen.requestFocus();
            return;
        }


        String SubGrupoRegimen = this.jTextFieldSubGrupoRegimen.getText();
        if (SubGrupoRegimen == null || SubGrupoRegimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el nombre de subgrupo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldIdSubGrupoRegimen.requestFocus();
            return;
        }


        String sValor = this.jTextFieldValor.getText();
        double Valor = Double.parseDouble(sValor);
        if (Valor <= 0) {
            JOptionPane.showMessageDialog(this, "El valor no debe ser menor de 0.", "Mensaje", JOptionPane.WARNING_MESSAGE);
            this.jTextFieldValor.setText("");
            jTextFieldValor.requestFocus();
            return;
        }
        String sLimiteInferior = this.jTextFieldLimiteInferior.getText();
        double LimiteInferior = Double.parseDouble(sLimiteInferior);
        if (LimiteInferior <= 0) {
            JOptionPane.showMessageDialog(this, "El limite inferior no debe ser negativo.", "Mensaje", JOptionPane.WARNING_MESSAGE);
            this.jTextFieldLimiteInferior.setText("");
            jTextFieldLimiteInferior.requestFocus();
            return;
        }
        String sLimiteSuperior = this.jTextFieldLimiteSuperior.getText();
        double LimiteSuperior = Double.parseDouble(sLimiteSuperior);
        if (LimiteSuperior <= 0) {
            JOptionPane.showMessageDialog(this, "El limite superior no debe ser negativo.", "Mensaje", JOptionPane.WARNING_MESSAGE);
            this.jTextFieldLimiteSuperior.setText("");
            jTextFieldLimiteSuperior.requestFocus();
            return;
        }
        if (Valor < LimiteInferior) {
            JOptionPane.showMessageDialog(this, "El Valor no debe ser menor que el limite inferior.", "Mensaje", JOptionPane.WARNING_MESSAGE);
            this.jTextFieldValor.setText("");
            jTextFieldValor.requestFocus();
            return;

        }
        if (Valor > LimiteSuperior) {
            JOptionPane.showMessageDialog(this, "El Valor no debe ser mayor que el limite superior.", "Mensaje", JOptionPane.WARNING_MESSAGE);
            this.jTextFieldValor.setText("");
            jTextFieldValor.requestFocus();
            return;

        }

        if (LimiteInferior > LimiteSuperior) {
            JOptionPane.showMessageDialog(this, "El limite inferior debe ser menor que el superior", "Mensaje", JOptionPane.WARNING_MESSAGE);
            this.jTextFieldLimiteInferior.setText("");
            jTextFieldLimiteInferior.requestFocus();
            return;

        }



        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String sqlquery = "select * from regimen where idmunicipio = ? and idregimen =?";
        PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
        psquery.setString(1, sesion.getIdmunicipio());
        psquery.setString(2, idRegimen);
        ResultSet rs = psquery.executeQuery();
        rs.next();
        int x = rs.getRow();

        if (x == 0) {
            JOptionPane.showMessageDialog(this, "No existe un regimen  con ese codigo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);

            return;
        }

        String Descripcion = jTextFieldDescripcion.getText();
        String Observacion = jTextAreaObservacion.getText();
        String sql = "update regimen set regimen = ?, idsubgruporegimen = ?, descripcion = ?, valor = ?,observacion = ?, limiteinferior = ?, limitesuperior = ? where idregimen= ? and idmunicipio=? and activo='si'";
        PreparedStatement prest = sesion.con.prepareStatement(sql);

        prest.setString(1, Regimen);
        prest.setString(2, idSubGrupoRegimen);
        prest.setString(3, Descripcion);
        prest.setDouble(4, Valor);
        prest.setString(5, Observacion);
        prest.setDouble(6, LimiteInferior);
        prest.setDouble(7, LimiteSuperior);
        prest.setString(8, idRegimen);
        prest.setString(9, sesion.getIdmunicipio());
        int count = prest.executeUpdate();
        sesion.con.close();
        JOptionPane.showMessageDialog(this, "Regimen Actualizado exitosamente", "Mensaje", JOptionPane.INFORMATION_MESSAGE);

        regimenBeans.setIdRegimen(idRegimen);
        regimenBeans.setIdSubGrupoRegimen(idSubGrupoRegimen);
        regimenBeans.setRegimen(Regimen);
        regimenBeans.setValor(Valor);
        regimenBeans.setLimiteInferior(LimiteInferior);
        regimenBeans.setLimiteSuperior(LimiteSuperior);
        regimenBeans.setDescripcion(Descripcion);
        regimenBeans.setObservacion(Observacion);
    } catch (Exception ex) {
        System.out.println("Error" + ex);
        JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonGuardarActionPerformed

private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
    // TODO add your handling code here:
     if (focoRegimen) {
                ActualizarRegimen();
            }
     if (focoSubGrupo) {
      CargarSubGrupos();
            }
     focoRegimen = false;
     focoSubGrupo = false;
}//GEN-LAST:event_formWindowGainedFocus

private void jTextFieldIdRegimenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldIdRegimenActionPerformed
    // TODO add your handling code here:
    ConsultarRegimen();
}//GEN-LAST:event_jTextFieldIdRegimenActionPerformed

private void jTextFieldIdSubGrupoRegimenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldIdSubGrupoRegimenActionPerformed
    // TODO add your handling code here:
       ConsultarSubGrupoRegimen();
}//GEN-LAST:event_jTextFieldIdSubGrupoRegimenActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new RegimenActualizarFrame().setVisible(true);
            }
        });
    }

    private void ConsultarRegimen(){
        try {
        String IdRegimen = this.jTextFieldIdRegimen.getText();
        if (IdRegimen == null || IdRegimen.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el codigo del regimen", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        String sqlquery = "select regimen.* from regimen where regimen.idmunicipio = ? and idregimen = ?";
        PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
        psquery.setString(1, sesion.getIdmunicipio());
        psquery.setString(2, IdRegimen);
        ResultSet rs = psquery.executeQuery();
        rs.next();
        int x = rs.getRow();
        if (x == 0) {
            JOptionPane.showMessageDialog(this, "No existen registros de regimen con ese codigo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            Limpiar();
            return;
        }
        String activo = rs.getString("activo");
        if (activo.equals("no")) {
            JOptionPane.showMessageDialog(this, "Este regimen esta inactivo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String IdSubGrupoRegimen = rs.getString("idsubgruporegimen");
        String Regimen = rs.getString("regimen");
        double Valor = rs.getDouble("valor");
        double LimiteInferior = rs.getDouble("limiteinferior");
        double LimiteSuperior = rs.getDouble("limiteSuperior");

        if (Regimen == null || Regimen.equals("")) {
            JOptionPane.showMessageDialog(this, "El regimen esta en blanco", "Mensaje", JOptionPane.WARNING_MESSAGE);
            return;
        }

        String descripcion = rs.getString("descripcion");
        String observacion = rs.getString("observacion");
        regimenBeans.setIdRegimen(IdRegimen);
        regimenBeans.setIdSubGrupoRegimen(IdSubGrupoRegimen);
        regimenBeans.setRegimen(Regimen);
        regimenBeans.setValor(Valor);
        regimenBeans.setLimiteInferior(LimiteInferior);
        regimenBeans.setLimiteSuperior(LimiteSuperior);
        regimenBeans.setDescripcion(descripcion);
        regimenBeans.setObservacion(observacion);
        this.jTextFieldRegimen.setText(Regimen);

        ActualizarRegimen();
        repaint();

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
    }
    private void ActualizarRegimen() {
        jTextFieldIdRegimen.setText(regimenBeans.getIdRegimen());
        jTextFieldRegimen.setText(regimenBeans.getRegimen());
        jTextFieldDescripcion.setText(regimenBeans.getDescripcion());
        jTextAreaObservacion.setText(regimenBeans.getObservacion());
        jTextFieldLimiteInferior.setText(String.valueOf(regimenBeans.getLimiteInferior()));
        jTextFieldLimiteSuperior.setText(String.valueOf(regimenBeans.getLimiteSuperior()));
        jTextFieldValor.setText(String.valueOf(regimenBeans.getValor()));
        jTextFieldIdSubGrupoRegimen.setText(regimenBeans.getIdSubGrupoRegimen());
        ConsultarSubGrupoRegimen();
    }

    private void Limpiar() {
        jTextFieldIdRegimen.setText("");
        jTextFieldRegimen.setText("");

        jTextFieldDescripcion.setText("");
        jTextAreaObservacion.setText("");
        jTextFieldLimiteInferior.setText("");
        jTextFieldLimiteSuperior.setText("");
        jTextFieldValor.setText("");
        jTextFieldIdSubGrupoRegimen.setText("");
        jTextFieldSubGrupoRegimen.setText("");
    }

    public void CargarSubGrupos() {
        try {

            this.jTextFieldIdSubGrupoRegimen.setText(subGrupoRegimenBeans.getIdSubGrupoRegimen());
            this.jTextFieldSubGrupoRegimen.setText(subGrupoRegimenBeans.getSubGrupo());

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void ConsultarSubGrupoRegimen() {
        try {
            String idSubGrupoRegimen = this.jTextFieldIdSubGrupoRegimen.getText();
            if (idSubGrupoRegimen == null || idSubGrupoRegimen.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese el codigo del subgrupo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            String sqlquery = "select * from subgruporegimen where idmunicipio = ? and idsubgruporegimen = ?";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            psquery.setString(1, sesion.getIdmunicipio());
            psquery.setString(2, idSubGrupoRegimen);
            ResultSet rs = psquery.executeQuery();
            rs.next();
            int x = rs.getRow();
            if (x == 0) {
                JOptionPane.showMessageDialog(this, "No existen registros de subgrupo con ese codigo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String activo = rs.getString("activo");
            if (activo.equals("no")) {
                JOptionPane.showMessageDialog(this, "Este registro esta inactivo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String subgrupo = rs.getString("subgrupo");

            if (subgrupo == null || subgrupo.equals("")) {
                JOptionPane.showMessageDialog(this, "El grupo esta en blanco", "Mensaje", JOptionPane.WARNING_MESSAGE);
                return;
            }
            subGrupoRegimenBeans.setIdSubGrupoRegimen(idSubGrupoRegimen);
            subGrupoRegimenBeans.setSubGrupo(subgrupo);
            this.jTextFieldIdSubGrupoRegimen.setText(idSubGrupoRegimen);
            this.jTextFieldSubGrupoRegimen.setText(subgrupo);
            repaint();

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonBuscarRegimen;
    private javax.swing.JButton jButtonBuscarSubGrupo;
    private javax.swing.JButton jButtonConsultarRegimen;
    private javax.swing.JButton jButtonConsultarSubGrupoRegimen;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JButton jButtonLimpiar;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextAreaObservacion;
    private javax.swing.JTextField jTextFieldDescripcion;
    private javax.swing.JTextField jTextFieldIdRegimen;
    private javax.swing.JTextField jTextFieldIdSubGrupoRegimen;
    private javax.swing.JTextField jTextFieldLimiteInferior;
    private javax.swing.JTextField jTextFieldLimiteSuperior;
    private javax.swing.JTextField jTextFieldRegimen;
    private javax.swing.JTextField jTextFieldSubGrupoRegimen;
    private javax.swing.JTextField jTextFieldValor;
    // End of variables declaration//GEN-END:variables
}
